# -*- coding: utf-8 -*-
"""
@author: wyb
@date: 2024/1/10
@time: 22:17
@desc: Description
"""
import requests, json


def getStockList(url):
    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'
    }
    # POST请求的目标URL
    # url = 'https://xueqiu.com/service/screener/screen?category=CN&exchange=sh_sz&areacode=&indcode=&order_by=symbol&order=desc&page=1&size=30&only_count=0&current=&pct=&pettm=1_39551.51&_=1704987103724'

    response = requests.get(url, headers=headers)
    response.raise_for_status()
    stockList = []

    # 处理API响应
    if response.status_code == 200:
        result = response.text
        data = json.loads(result)
        list = data['data']['list']
        stockList = [{'symbol': obj['symbol'], 'name': obj['name']} for obj in list]
        print(stockList)
        return stockList
    else:
        print(f"Error: {response.status_code}")

